﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using Microsoft.Research.Kinect.Nui;

using SkeletalViewer;

public class ControladorImagen
{
    public Imagen imagen;
    Image imageControl;
    public ControladorImagen(Imagen imagen)
	{
        this.imagen = imagen;
        
	}
    public void dibujarImagenEnCanvas(Canvas canvas, double posIZQ, double posSuperior)
    {
        ImageDrawing trazoImagen = new ImageDrawing();
        trazoImagen.Rect = new Rect((double)0, (double)0, imagen.obtenerAncho(), imagen.obtenerAltura());
        trazoImagen.ImageSource = new BitmapImage(new Uri(imagen.obtenerUbicacion(), UriKind.Relative));
        DrawingGroup imageDrawings = new DrawingGroup();
        imageDrawings.Children.Add(trazoImagen);

        DrawingImage drawingImageSource = new DrawingImage(imageDrawings);
        imageControl = new Image();
        imageControl.Stretch = Stretch.None;
        imageControl.SetValue(Canvas.LeftProperty, posIZQ);
        imageControl.SetValue(Canvas.TopProperty, posSuperior);
        imageControl.Source = drawingImageSource;
        canvas.Children.Add(imageControl);
    }
    public Imagen obtenerImagen() {
        return this.imagen;
    }
    public void dibujarImagenCentrada(Canvas skeleton)
    {
        dibujarImagenEnCanvas(skeleton, coordenadaX(skeleton.Width), coordenadaY(skeleton.Height));
    }
    public double coordenadaX(double ancho)
    {
        return (ancho/2)-(imagen.obtenerAncho()/2);
    }
    public double coordenadaY(double alto)
    {
        return (alto / 2) - (imagen.obtenerAncho() / 2);
    }

    public void cambiarPosicion(Canvas skeleton, double Left, double Top)
    {
        imageControl.SetValue(Canvas.LeftProperty, Left);
        imageControl.SetValue(Canvas.TopProperty, Top);
    }
}
